Skip to content

fix(redirects): manage Render routes in code via API (200-cap + wildcard consolidation)#73

Closed
a-thomas-22 wants to merge 1 commit into
zerodevapp:mainfrom
a-thomas-22:at/render-routes-api-sync
Closed

fix(redirects): manage Render routes in code via API (200-cap + wildcard consolidation)#73
a-thomas-22 wants to merge 1 commit into
zerodevapp:mainfrom
a-thomas-22:at/render-routes-api-sync

Conversation

@a-thomas-22

Copy link
Copy Markdown
Contributor

Root cause (finally)

Two hard Render constraints, confirmed empirically + via Render docs:

  1. A static site is capped at 200 routes. Our set was 215 → the Blueprint sync failed on "Update web service routes". (The earlier "bad rule" /resources/infrastructure/api was a red herring — it was simply route #201.)
  2. Blueprints MERGE routes and never delete them. So render.yaml-defined routes accumulate and drift, and can't be cleanly curated.

Together these make the Blueprint a poor place to own a redirect set. So routes move into code, applied via the Render API.

Approach

  • redirects.config.js stays the single source of truth (202 entries).
  • scripts/sync-render-routes.mjs consolidates to 116 routes and applies them via PUT /v1/services/{id}/routes (atomic replace — deletes anything not in the list, priority = list order):
    • 11 verified prefix-swap wildcard collapses (e.g. /react/* → /advanced/react-hooks/*, /resources/* → /api-and-toolings/*) replace 97 individual redirects. Each collapse is checked at build time — if any member isn't a clean tail-preserving swap, it's skipped and stays individual.
    • 94 individual redirects + the SPA-fallback rewrites, ordered redirects before rewrites (Render is first-match-by-priority), deduped by source.
    • Build fails if the result exceeds 200 routes or has duplicate sources.
  • .github/workflows/render-routes.yml validates on every PR (no secrets) and applies on push to main (needs RENDER_API_KEY + RENDER_SERVICE_ID secrets).
  • render.yaml keeps only service config (build/domains/env) — no routes block, so the Blueprint manages infra and never fights the API-managed routes.
  • Removes the obsolete render.yaml splice script and redirects-in-sync workflow.

Behavior note

The 11 collapses are catch-alls (e.g. any /react/... now redirects to /advanced/react-hooks/...), so unlisted sub-paths redirect too instead of 404ing — generally an improvement. All 201 originally-mapped URLs resolve identically.

Verified end-to-end

On a throwaway Render static site, the 116-route set PUT succeeded and legacy URLs return correct 301s:

/sdk/getting-started/quickstart        -> 301 /get-started/quickstart
/resources/infrastructure/api          -> 301 /api-and-toolings/infrastructure/api   (via /resources/* wildcard)
/react/use-kernelclient                -> 301 /advanced/react-hooks/use-kernelclient  (wildcard tail)
/smart-wallet/permissions/policies/gas -> 301 /smart-accounts/permissions/policies/gas

Before this works in prod

  1. Add repo secrets RENDER_API_KEY and RENDER_SERVICE_ID (srv-cm3hg30cmk4c73cd5nd0).
  2. First apply replaces the prod service's current routes with the 116-route set.

…ard consolidation)

Render caps a static site at 200 routes, and its Blueprint MERGES routes and
never deletes them, so the 215-route set could never sync cleanly. Move route
management out of the Blueprint and into code applied via the Render API:

- redirects.config.js stays the single source of truth (202 entries).
- scripts/sync-render-routes.mjs consolidates to 116 routes (11 verified
  prefix-swap wildcard collapses + 94 individuals + SPA fallbacks, ordered
  redirects-before-rewrites, deduped) and PUTs them to Render (atomic replace,
  PUT /v1/services/{id}/routes), which deletes anything not in the list.
- .github/workflows/render-routes.yml validates the set on every PR and applies
  it on push to main (needs RENDER_API_KEY + RENDER_SERVICE_ID secrets).
- render.yaml keeps only service config (no routes block).
- Remove the obsolete render.yaml splice script + redirects-in-sync workflow.

Verified end-to-end on a throwaway Render service: the 116-route set PUT
successfully and legacy URLs (including wildcard tails) return 301s.
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@a-thomas-22 is attempting to deploy a commit to the zero-dev1 Team on Vercel.

A member of the Team first needs to authorize it.

@a-thomas-22 a-thomas-22 marked this pull request as draft June 26, 2026 18:07
@a-thomas-22 a-thomas-22 deleted the at/render-routes-api-sync branch June 26, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant